package cn.edu.hqu.wel.shiyan2.service.impl;

import cn.edu.hqu.wel.shiyan2.mapper.OrderMapper;
import cn.edu.hqu.wel.shiyan2.model.Order;
import cn.edu.hqu.wel.shiyan2.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    private final OrderMapper orderMapper;

    @Autowired
    public OrderServiceImpl(OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }

    @Override
    public List<Order> getAllOrders() {
        return orderMapper.selectList(null);
    }

    @Override
    public Order getOrderById(Long id) {
        return orderMapper.selectById(id);
    }

    @Override
    public Order createOrder(Order order) {
        orderMapper.insert(order);
        return order;
    }

    @Override
    public Order updateOrder(Order order) {
        orderMapper.updateById(order);
        return order;
    }

    @Override
    public void deleteOrder(Long id) {
        orderMapper.deleteById(id);
    }
}
